<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="../inc/TagLibs.jsp"%>
<c:set var="pageTitle" value="生产进度管理" />
<%@ include file="../inc/Title.jsp"%>
<head>
<link href="/css/Query.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="/css/BillList.css" />
<script src="/js/QueryList.js"></script>
<script src="/js/popup_ext.js"></script>
<script language="javascript">
	function doJump(pageIndex){
		if(window.event.keyCode==13){
			doGo(pageIndex);
		}
	}
	function doCancel(){
		window.close();
	}
	function doInit(){
		//Window_Onload();
		if(window.screen.availWidth>1024){
			var w=window.screen.availWidth*0.98;
			window.resizeTo(w,600);
			//居中
			var resizeWinTop=(window.screen.availHeight-600)/2;
			var resizeWinLeft=(window.screen.availWidth-w)/2;
			window.moveTo(resizeWinLeft,resizeWinTop);
		}
	}
	function createPageParaStr(){
		var str="dep_id="+document.getElementById("dep_id").value;
		str=str+"&est_name="+encodeURIComponent(document.getElementById("est_name").value);
		str=str+"&bill_code="+encodeURIComponent(document.getElementById("bill_code").value);
		str=str+"&ts_id="+document.getElementById("ts_id").value;
		str=str+"&cont="+encodeURIComponent(document.getElementById("cont").value);
		str=str+"&wc_id="+document.getElementById("wc_id").value;
		return str;
	}
	
	function createProgramParaStr(){
		var str="dep_id=${depId}";
		str=str+"&est_name="+encodeURIComponent(document.getElementById("hid_est_name").value);
		str=str+"&bill_code="+encodeURIComponent(document.getElementById("hid_bill_code").value);
		str=str+"&ts_id=${tsId}";
		str=str+"&cont="+encodeURIComponent(document.getElementById("hid_cont").value);
		str=str+"&wc_id=${wcId}";
		return str;
	}
	function doSearch(){
		var str;
		if(IsAdvSearch){//高级
			str="search_type=1";
			//if(document.getElementById("cb_dep").checked){
				var depId=document.getElementById("dep_id").value;
				if(depId==null || depId=="" || depId=="0"){
					ShowAlert('提示框','请选择部门',200,100);
					return;
				}
				str=str+"&cb_dep=1";
			//}
			if(document.getElementById("cb_bill_code").checked){
				var billCode=document.getElementById("bill_code").value.trim();
				if(billCode==null || billCode==""){
					ShowAlert('提示框','请输入业务单号',200,100);
					return;
				}
				str=str+"&cb_bill_code=1";
			}
			if(document.getElementById("cb_cont").checked){
				var cont=document.getElementById("cont").value.trim();
				if(cont==null || cont==""){
					ShowAlert('提示框','请输入内容',200,100);
					return;
				}
				str=str+"&cb_cont=1";
			}
			if(document.getElementById("cb_wc").checked){
				var wcId=document.getElementById("wc_id").value;
				if(wcId==null || wcId=="" || wcId=="0"){
					ShowAlert('提示框','请选择工作中心',200,100);
					return;
				}
				str=str+"&cb_wc=1";
			}
			if(document.getElementById("cb_est").checked){
				var estName=document.getElementById("est_name").value.trim();
				if(estName==null || estName==""){
					ShowAlert('提示框','请输入订货单位名称',200,100);
					return;
				}
				str=str+"&cb_est=1";
			}
			if(document.getElementById("cb_ts").checked){
				var tsId=document.getElementById("ts_id").value;
				if(tsId==null || tsId=="" || tsId=="0"){
					ShowAlert('提示框','请选择帐套',200,100);
					return;
				}
				str=str+"&cb_ts=1";
			}
		}else{//快速
			str="search_type=2";
			var depId=document.getElementById("dep_id").value;
			if(depId==null || depId=="" || depId=="0"){
				ShowAlert('提示框','请选择部门',200,100);
				return;
			}
		}
		var paraStr=createPageParaStr();
		if(paraStr!=""){
			str=str+"&"+paraStr;
		}
		window.location="/make/BusinessBillListForTask.ihtm?"+str;
	}
	function doGo(pageIndex){
		var str=getSearchCondition();
		str=str+"&current_page="+pageIndex;
		window.location="/make/BusinessBillListForTask.ihtm?"+str;
	}
	function getSearchCondition(){
		var searchType="${searchType}";
		var str="search_type="+searchType;
		if(searchType=="1"){//高级
			<c:if test="${cbDep=='1'}">str=str+"&cb_dep=1";</c:if>
			<c:if test="${cbEst=='1'}">str=str+"&cb_est=1";</c:if>
			<c:if test="${cbBillCode=='1'}">str=str+"&cb_bill_code=1";</c:if>
			<c:if test="${cbTs=='1'}">str=str+"&cb_ts=1";</c:if>
			<c:if test="${cbCont=='1'}">str=str+"&cb_cont=1";</c:if>
			<c:if test="${cbWc=='1'}">str=str+"&cb_wc=1";</c:if>
		}else{//快速
			
		}
		var paraStr=createProgramParaStr();
		if(paraStr!=""){
			str=str+"&"+paraStr;
		}
		return str;
	}
	function DoubleClick(it){
		
	}
	function doAutoCheck(objId){
		document.getElementById(objId).checked=true;
	}
	function checkInput(){
		if(window.event.keyCode==13){
			doSearch();
		}
	}
	function doProComp(billId,itemId,proId){
		ShowConfirm('确认框','确定设置为本道工序完工吗？',340,80,"doProCompCallBack('"+billId+"','"+itemId+"','"+proId+"')");
	}
	function doProCompCallBack(billId,itemId,proId){
		if(popRetVal!=null){
			var url="/make/BusinessProComplete.ihtm?bill_id="+billId+"&item_id="+itemId+"&pro_id="+proId;
			ShowIframe("请稍候...",url,200,200,"refreshWin()");
		}
	}
	function refreshWin(){
		if(popRetVal!=null){
			window.location.reload(true);
		}
	}
	function doProBack(billId,itemId,proId){
		ShowConfirm('确认框','确定退回上道工序吗？',340,80,"doProBackCallBack('"+billId+"','"+itemId+"','"+proId+"')");
	}
	function doProBackCallBack(billId,itemId,proId){
		if(popRetVal!=null){
			var url="/make/BusinessProBack.ihtm?bill_id="+billId+"&item_id="+itemId+"&pro_id="+proId;
			ShowIframe("请稍候...",url,200,200,"refreshWin()");
		}
	}
	function doMultiComp(){
		var ob_arr = document.getElementsByName("query_checkbox");
		var billId="",itemId="",proId="";
		for (i=0;i<ob_arr.length;i++){
			if ((ob_arr[i].checked == true)){
				if(billId!=""){
					billId=billId+";";
				}
				if(itemId!=""){
				   itemId=itemId+";";
				}
				if(proId!=""){
				   proId=proId+";";
				}
				billId = billId+ob_arr[i].value;
				itemId = itemId+ob_arr[i].getAttribute("item_id");
				proId = proId+ob_arr[i].getAttribute("pro_id");
			}
		}
		if(billId!=""){
			ShowConfirm('确认框','确定设置为本道工序完工吗？',340,80,"doMultiCompCallBack('"+billId+"','"+itemId+"','"+proId+"')");
		}else{
			ShowAlert('提示框','请选择要完工的项目',200,100);
		}
	}
	function doMultiCompCallBack(billId,itemId,proId){
		if(popRetVal!=null){
			var url="/make/BusinessProComplete.ihtm?bill_id="+billId+"&item_id="+itemId+"&pro_id="+proId;
			ShowIframe("请稍候...",url,200,200,"refreshWin()");
		}
	}
	function doMultiBack(){
		var ob_arr = document.getElementsByName("query_checkbox");
		var billId="",itemId="",proId="";
		for (i=0;i<ob_arr.length;i++){
			if ((ob_arr[i].checked == true)){
				if(billId!=""){
					billId=billId+";";
				}
				if(itemId!=""){
				   itemId=itemId+";";
				}
				if(proId!=""){
				   proId=proId+";";
				}
				billId = billId+ob_arr[i].value;
				itemId = itemId+ob_arr[i].getAttribute("item_id");
				proId = proId+ob_arr[i].getAttribute("pro_id");
			}
		}
		if(billId!=""){
			ShowConfirm('确认框','确定将所选项目退回上道工序吗？',340,80,"doMultiBackCallBack('"+billId+"','"+itemId+"','"+proId+"')");
		}else{
			ShowAlert('提示框','请选择要退回的项目',200,100);
		}
	}
	function doMultiBackCallBack(billId,itemId,proId){
		if(popRetVal!=null){
			var url="/make/BusinessProBack.ihtm?bill_id="+billId+"&item_id="+itemId+"&pro_id="+proId;
			ShowIframe("请稍候...",url,200,200,"refreshWin()");
		}
	}
	function doDownload(){
		var str=getSearchCondition();
		window.location="/make/BusinessBillListForTask.ihtm?content_type=EXCEL&"+str;
	}
	function doOutput(itemId,wcId,proId){
		var url="/base/StafferMainForSelect.ihtm?type=MULTI";
		ShowIframe("选择员工",url,800,500,"doOutputCallBack('"+itemId+"','"+wcId+"','"+proId+"')");
	}
	function doOutputCallBack(itemId,wcId,proId){
		if(popRetVal!=null){
			var idStr="";
			var nameStr="";
			for(i=0;i<popRetVal.length;i++){
				if(idStr!=""){
					idStr=idStr+";";
					nameStr=nameStr+";";
				}
				idStr=idStr+popRetVal[i][0];
				nameStr=nameStr+popRetVal[i][2];
			}
			if(idStr!=""){
				var url="/make/OutputMultiForm.ihtm?from_type=TASK&item_id="+itemId+"&wc_id="+wcId+"&pro_id="+proId+"&id_str="+idStr+"&name_str="+encodeURIComponent(nameStr);
				ShowIframe("产量登记",url,400,300,"refreshWin()",1024,600);
			}
		}
	}
	function showList(wcId){
		var str="search_type=1&cb_wc=1&wc_id="+wcId+"&cb_dep=1&dep_id="+document.getElementById("dep_id").value;
		window.location="/make/BusinessBillListForTask.ihtm?"+str;
	}
	function showSmsSubscribe(){
		<c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';SMS_SUBS;')!=-1}">
		showWin(520,640,'/sms/SmsSubscribe.ihtm');
		</c:if>
		<c:if test="${currentUser.user.userType!=1 && fn:indexOf(currentUser.privs,';SMS_SUBS;')==-1}">
		ShowAlert('提示框','对不起，您还没有短信订阅设置权限。',200,100);
		</c:if>
	}
	function showAccessories(id,wcId,billCode){
		var url="/make/AccessoryListAlone.ihtm?acc_type=DESIGN&agent_type=BUSINESS_BILL&agent_id="+id+"&ext_id="+wcId+"&mark="+encodeURIComponent("业务单："+billCode);
		ShowIframe("图样",url,900,500);
	}
	function selectEstName(){
		var url="/base/EstablishmentListForSelect.ihtm?type=CLIENT";
		ShowIframe("选择客户",url,900,500,"selectEstNameCallBack()");
	}
	function selectEstNameCallBack(){
		if(popRetVal!=null){
			document.getElementById("est_name").value=popRetVal[1];
			doAutoCheck("cb_est");
		}
	}
	function setCurPro(billId,itemId,wcId){
		var url="/base/WorkProcessListForSelect.ihtm?wc_id="+wcId;
		ShowIframe('选择工序',url,300,400,"setCurProCallBack('"+billId+"','"+itemId+"','"+wcId+"')");
	}
	function setCurProCallBack(billId,itemId,wcId){
		if(popRetVal!=null){
			var url="/make/BusinessProSet.ihtm?bill_id="+billId+"&item_id="+itemId+"&wc_id="+wcId+"&pro_id="+popRetVal[0];
			ShowIframe("请稍候...",url,200,200,"refreshWin()");
		}
	}
</script>
</head>
<body oncontextmenu="return false">
<div class="Wrap"><!-- 页面主框架 -->
    
	<div id="ListContainer" class="Container"><!-- 主体容器 -->
	    
	    <!-- 标题栏 -->
	    <div class="Heading BillIcon">
	        <div class="HeadingContent">
	            <h1>生产进度管理</h1>
	            <span class="Note">已开工的业务单才进入生产进度管理，用于管理当前工序需要制作的项目，上一道工序未完工，本道工序将不会出现。</span>
	        </div>
	    </div>
	
		<!-- 主内容 -->
		<div class="Content">
	        <!-- 筛选控件栏 -->
	        <div class="FilterBar ClearFix">
	            <div class="SearchIcon"></div>
	            <span class="fl">
	            	<table class="MoreOption" cellpadding="0" cellspacing="0">
	            		<th class="c1" width="80px">
	            			<input type="checkbox" name="cb_dep" id="cb_dep" checked="true" disabled="disabled" style="visibility:hidden;" />
	            			部门
	            		</th>
	            		<td class="c1" width="260px">
	            			<select name="dep_id" id="dep_id" onFocus="doAutoCheck('cb_dep');" onChange="doSearch();">
								<option value="0">==请选择==</option>
								<commonTag:createSelectTree list="${depList}" emptyOption="0" defaultValue="${depId}" />
						  	</select>
	            		</td>
	            	</table>
	            </span>
				<span class="fr">
	            	<a href="javascript:;" id="lnkMoreOption">更多查询选项</a>
	            	<c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';SMS_SUBS;')!=-1}">
					<!-- <a href="javascript:showSmsSubscribe();" style="color:green" title="设置工序开工、完工、退回等消息提醒。">设置消息提醒</a> -->
					</c:if>
				  	<input type="button" value=" 查 询" onClick="doSearch();" class="buttom search-but" id="sSearchButton" name="sSearchButton">
				  	<input type="button" value=" 工序完工" onClick="doMultiComp();" class="buttom search-audit" id="sCompButton" name="sCompButton" title="把选中的项目标记为完工，进入下一道工序">
				  	<input type="button" value=" 退 回" onClick="doMultiBack();" class="buttom search-back" id="sBackButton" name="sBackButton" title="把选中的项目退回上道工序">
				  	<input type="button" value=" 导 出" onClick="doDownload();" class="buttom search-out" id="sDownButton" name="sDownButton" <c:if test="${currentUser.user.userType!=1 && fn:indexOf(currentUser.privs,';NO_EXPO;')!=-1}">disabled="true"</c:if>>
	            </span>
				<div id="dvMoreOptionBox" class="MoreOptionBox" style="display:none;">
					<table class="MoreOption" cellpadding="0" cellspacing="0">
						<tr>
							<th class="c1" width="80px">
			        			<input type="checkbox" name="cb_bill_code" id="cb_bill_code" <c:if test="${cbBillCode=='1'}">checked="true"</c:if>>
			        			业务单号
			        		</th>
			    			<td class="c1" width="240px">
			        			<input type="text" class="TextBox" maxlength="50" name="bill_code" id="bill_code" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_bill_code');" value="<c:out value="${billCode}" />" >
								<input type="hidden" id="hid_bill_code" value="<c:out value="${billCode}" />">
			    			</td>
			    			<th class="c2" width="80px">
			        			<input type="checkbox" name="cb_wc" id="cb_wc" <c:if test="${cbWc=='1'}">checked="true"</c:if>>
			        			工作中心
			        		</th>
			    			<td class="c3" width="280px">
			        			<select name="wc_id" id="wc_id" onFocus="doAutoCheck('cb_wc');" onChange="doWcIdChange();">
					  				<option value="0">==请选择==</option>
					  				<c:forEach var="item" items="${wcList}">
					  				<option value="${item.id}" <c:if test="${wcId==item.id}">selected</c:if>>${item.wcName}</option>
					  				</c:forEach>
								</select>
			    			</td>
			    		</tr>
			    		<tr>
			    			<th class="c1">
			        			<input type="checkbox" name="cb_cont" id="cb_cont" <c:if test="${cbCont=='1'}">checked="true"</c:if>>
			        			内容
			        		</th>
			        		<td class="c1">
			        			<input type="text" class="TextBox" maxlength="50" name="cont" id="cont" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_cont');" value="<c:out value="${cont}" />" >
								<input type="hidden" id="hid_cont" value="<c:out value="${cont}" />">
			    			</td>
							<th class="c2">
			        			<input type="checkbox" name="cb_est" id="cb_est" <c:if test="${cbEst=='1'}">checked="true"</c:if>>
			        			订货单位
			        		</th>
			    			<td class="c3">
			        			<input type="text" class="TextBox" maxlength="50" name="est_name" id="est_name" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_est');" value="<c:out value="${estName}" />" >
								<img class="imgIconButton" src="/images/make-a.gif" onClick="selectEstName();" />
								<input type="hidden" id="hid_est_name" value="<c:out value="${estName}" />">
			    			</td>
						</tr>
						<tr>
							<th class="c1">
			        			<input type="checkbox" name="cb_ts" id="cb_ts" <c:if test="${cbTs=='1'}">checked="true"</c:if>>
	                        	账套
			        		</th>
			    			<td class="c1">
			        			<select name="ts_id" id="ts_id" onFocus="doAutoCheck('cb_ts');">
				    				<option value="0">==请选择账套==</option>
				    				<c:forEach var="item" items="${tsList}">
									<option value="${item.id}" <c:if test="${tsId==item.id}">selected</c:if>>${item.title}</option></c:forEach>
								</select>
			        		</td>
			        		<th class="c2">&nbsp;</th>
	                    	<td class="c2">&nbsp;</td>
						</tr>
					</table>
					
					<div class="OptionOrderBy">
						<span class="fr"><a href="javascript:;" id="lnkHiddenOption">隐藏查询选项</a></span>
	                </div>
				</div>
			</div>
			
			<!-- 提示信息显示栏 -->
	        <div class="MsgBar">
	            <%@include file="../inc/AlertMsg.jsp"%>
	        </div>
	        
	        <!-- 上栏 分页、操作等 -->
	        <div class="TopToolBar">
	            <table class="ListNoteInfo" cellpadding="0" cellspacing="0">
	            	<tr>
	                	<td>
	                		任务数量：${qr.totalCount}
	                		选择：
	                		<c:forEach var="item" items="${wcList}">
	  							<a href="javascript:showList(${item.id});">${item.wcName}</a>
	  						</c:forEach>
						</td>
	            	</tr>
	            </table>
			</div>

		    <div class="table-list">
		        <table width="100%">
		          	<tr>
			          	<th width="14"><input type="checkbox" onClick="javascript:checkall(this);"></th>
						<th width="8%">日期</th>
						<th width="10%">单号</th>
						<th width="8%">订货单位</th>
						<th width="6%">项目类型</th>
						<th width="8%">内容</th>
						<th width="8%">材质</th>
						<th width="9%">规格</th>
						<th width="5%">单位</td>
						<th width="6%">数量</td>
						<th width="8%">制作要求</td>
						<th width="6%">当前工序</th>
						<th width="9%">完成情况</th>
						<th width="9%">操作</th>
		          	</tr> 
					<c:forEach var="item" items="${qr.list}" varStatus="i">
					<c:if test="${(i.index mod 2)==0}"><c:set var="trClass" value="query_list_data_tr1" /></c:if>
					<c:if test="${(i.index mod 2)!=0}"><c:set var="trClass" value="query_list_data_tr2" /></c:if>
					<c:set var="defaultFontColor" value="#000000" />
					<c:if test="${item[17]=='Y'}"><c:set var="defaultFontColor" value="red" /></c:if>
					<tr class="${trClass}" index="${i.index+1}" style="color:${defaultFontColor};cursor:pointer" defaultFontColor="${defaultFontColor}" onClick='javascript:ClickCheck(this,true)' ondblclick='javascript:DoubleClick(this)' onmouseout='javascript:mouseout(this)' onmouseover='javascript:mouseover(this)'>
						<td><input type="checkbox" onClick="javascript:ClickCheck(this,true);" name='query_checkbox' value="${item[0]}" item_id="${item[5]}" pro_id="${item[18]}"></td>
						<td><fmt:formatDate value="${item[1]}" pattern="yyyy-MM-dd"/></td>
						<td>${item[2]}</td>
						<td><c:if test="${currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';NO_CLIE_NAME;')==-1}">${item[4]}</c:if></td>
						<td><commonTag:showSimpleObjectName list="${mtList}" objectId="${item[6]}" /></td>
						<td>${item[7]}</td>
						<td>${item[8]}</td>
						<td>${item[9]}<c:if test="${item[13]=='AREA' || item[13]=='LENGTH'}"> x <commonTag:parseBigDecimal source="${item[11]}" /></c:if></td>
						<td>
							<c:if test="${item[13]=='AREA'}">平方米</c:if>
							<c:if test="${item[13]=='LENGTH'}">
								<c:if test="${item[22]=='M'}">米</c:if><c:if test="${item[22]=='CM'}">公分</c:if>
							</c:if>
							<c:if test="${item[13]=='AMOUNT'}">${item[10]}</c:if>
						</td>
						<td>
							<c:if test="${item[13]=='AREA' || item[13]=='LENGTH'}"><commonTag:parseBigDecimal source="${item[12]}" /></c:if>
							<c:if test="${item[13]=='AMOUNT'}"><commonTag:parseBigDecimal source="${item[11]}" /></c:if>
						</td>
						<td>${item[14]}</td>
						<td>${item[19]}</td>
						<td>${item[15]}</td>
						<td>
							<a href="javascript:setCurPro('${item[0]}','${item[5]}','${item[20]}');">修改生产进度</a>
							<br>
							<a href="javascript:doOutput('${item[5]}','${item[20]}','${item[18]}');">产量登记</a>
							<a href="javascript:showAccessories('${item[0]}','${item[20]}','${item[2]}');">图样</a>
							<br>
							<a href="javascript:doProComp('${item[0]}','${item[5]}','${item[18]}');">本道工序完工</a>
							<c:if test="${item[21]=='Y'}"><br><a href="javascript:doProBack('${item[0]}','${item[5]}','${item[18]}');">退回上道工序</a></c:if>
						</td>
					</tr>
					</c:forEach>
		        </table>
			</div>

			<!-- 底栏 分页、操作等 -->
	        <div class="BottomToolBar ClearFix">
			    <%@include file="../inc/Pages.jsp"%>
	        </div>
			
		</div>
	</div>
</div>
</body>
</html>
<script type="text/javascript">
	function ChangeWindowSize( container, maxWidth ){
	    setTimeout( function(){
	        var w1 = document.documentElement.clientWidth-40;
	        if( w1>maxWidth ) w1 = maxWidth;
	        else if( w1<970 ) w1 = 960;
	        container.style.width = w1+'px';
	    }, 300 );
	}
	var IsAdvSearch = false;
	(function(){
		doInit();
	    var ListContainer = document.getElementById('ListContainer');
	    ChangeWindowSize( ListContainer, 2020 );    // 超过 1280 的最大 1260 ，不全部铺满
	
	    var lnkMoreOption   = document.getElementById('lnkMoreOption');
	    var lnkHiddenOption = document.getElementById('lnkHiddenOption');
	    lnkMoreOption.onclick = function(){
	    	IsAdvSearch = true;
	        document.getElementById('dvMoreOptionBox').style.display = 'block';
	        document.getElementById('cb_dep').style.visibility = 'visible';
	        this.style.visibility = 'hidden';
	    };
	    lnkHiddenOption.onclick = function(){
	    	IsAdvSearch = false;
	        document.getElementById('dvMoreOptionBox').style.display = 'none';
	        document.getElementById('cb_dep').style.visibility = 'hidden';
	        lnkMoreOption.style.visibility = 'visible';
	    };
	})();
</script>
